<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/common_include_for_server.jsp"%>
<script type="text/javascript">
<!--
var saveKeywordDialog = null;
$(function(){
	// init save user dialog:
	saveKeywordDialog = $('#saveKeywordDialog').dialog({
		autoOpen: false, 
		resizable: false,
		modal: true,
		open: function(event, ui) {
			var keywordId = $('#saveKeywordForm input[name="keywordRecommended.keywordRecommendedId"]').val();
			if(keywordId.length == 0){
				saveKeywordDialog.dialog('option', 'title', '添加关键字');
			}else{
				saveKeywordDialog.dialog('option', 'title', '修改关键字');
			}
		},
		buttons: {
			"确定":function(){
				$.post('<%=request.getContextPath() %>/manage/report!keywordRecoSaveOrUpdate.action', 
					$('#saveKeywordForm').serialize(),
					function(){
						window.location.href = window.location.href;
				});
			},
			"取消":function(){ saveKeywordDialog.dialog('close'); }
		}
	});
});
function initSaveDialog(words,id){
	var wordsObj = $('#saveKeywordForm input[name="keywordRecommended.words"]');
	var idObj = $('#saveKeywordForm input[name="keywordRecommended.keywordRecommendedId"]');
	wordsObj.val('');
	idObj.val('');
	if(words){
		wordsObj.val(words);
	}
	if(id){
		idObj.val(id);
	}
	saveKeywordDialog.dialog('open');
}
function updateOrder(){
	$.post('<%=request.getContextPath() %>/manage/report!keywordUpdateOrder.action', 
			$('#keywordOrderForm').serialize(),
			function(){
				window.location.href = window.location.href;
	});
}
//-->
</script>
<s:a href="javascript:void(0);" onclick="initSaveDialog();">添加关键字</s:a>
<div id="saveKeywordDialog" style="display: none;">
    <s:form id="saveKeywordForm">
    	<input type="hidden" name="keywordRecommended.keywordRecommendedId"/>
    	关键字：<input type="text" name="keywordRecommended.words" />
    </s:form>
</div>
<form id="keywordOrderForm" action="#">
<table border="1">
	<tr>
		<th>
			关键字内容
		</th>
		<th>
			顺序号
		</th>
		<th>
			操作
		</th>
	</tr>
	<s:iterator value="keywordRecommendedList" status="sts">
		<tr>
			<td>
				<s:property value="words" />
			</td>
			<td>
				<s:hidden name="keywordRecommendedList[%{#sts.index}].keywordRecommendedId" value="%{keywordRecommendedId }"></s:hidden>
				<s:textfield name="keywordRecommendedList[%{#sts.index}].orderId" value="%{orderId }" size="6"/>
			</td>
			<td>
				<s:a href="javascript:void(0);" onclick="initSaveDialog('%{words }', '%{keywordRecommendedId}');">修改</s:a>
				<s:a href="manage/report!keywordRecoDelete.action?keywordRecommended.keywordRecommendedId=%{keywordRecommendedId}">删除</s:a>
			</td>
		</tr>
	</s:iterator>
		<tr>
			<td colspan="4"> <input type="button" value="更新顺序号" onclick="updateOrder();"/> </td>
		</tr>
</table>
</form>